﻿using System;

namespace Storm.TextEditor.Editor.Text
{
	/// <summary>
	/// Represents a point in the text of a TextEditor.
	/// </summary>
	public class TextPoint
	{
		#region Fields

		private int x = 0;
		private int y = 0;

		#region Events

		/// <summary>
		/// Occurs when the x or y coordinate of the TextPoint has changed.
		/// </summary>
		public event EventHandler Change = null;

		#endregion

		#endregion

		#region Properties

		/// <summary>
		/// Gets or sets the x coordinate of the TextPoint.
		/// </summary>
		public int X
		{
			get { return x; }
			set
			{
				x = value;
				this.OnChange();
			}
		}

		/// <summary>
		/// Gets or sets the y coordinate of the TextPoint.
		/// </summary>
		public int Y
		{
			get { return y; }
			set
			{
				y = value;
				this.OnChange();
			}
		}

		#endregion

		#region Methods

		#region Private

		/// <summary>
		/// Raises the Change event.
		/// </summary>
		private void OnChange()
		{
			if (this.Change != null)
				this.Change(this, new EventArgs());
		}

		#endregion

		#endregion

		/// <summary>
		/// Initializes a new instance of TextPoint.
		/// </summary>
		public TextPoint()
		{
		}

		/// <summary>
		/// Initializes a new instance of TextPoint.
		/// </summary>
		/// <param name="x">X coordinate of the TextPoint.</param>
		/// <param name="y">Y coordinate of the TextPoint.</param>
		public TextPoint(int x, int y)
		{
			this.X = x;
			this.Y = y;
		}
	}
}
